package cn.com.panda.base;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import cn.com.panda.utils.PermissionUtil;

public abstract class BaseActivity extends AppCompatActivity implements  ActivityCompat.OnRequestPermissionsResultCallback {

    protected static Context mContext;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext = this;
    }

    protected void toActivity(Class<?> cls,Bundle bundle){
        Intent intent = new Intent(mContext,cls);
        if(bundle != null)
            intent.putExtras(bundle);
        startActivity(intent);
    }

    protected void toActivityWithResult(Class<?> cls,Bundle bundle,int resultCode){
        Intent intent = new Intent(mContext,cls);
        if(bundle != null)
            intent.putExtras(bundle);
        startActivityForResult(intent,resultCode);
    }

    protected boolean isAllowPermission(String permission){
        PermissionUtil permissionUtil = new PermissionUtil(mContext);
        return permissionUtil.isAllowPermission(permission);
    }

    protected void requestPermission(AppCompatActivity mActivity, String permission){
        PermissionUtil permissionUtil = new PermissionUtil(mContext);
        permissionUtil.requestPermission(mActivity,permission);
    }

    protected abstract void checkPermissionResult(String[] permissions,int[] grantResults);

    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
                                    @NonNull int[] grantResults){
        checkPermissionResult(permissions,grantResults);
    }

}